﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using Water.Resources.Globalize;
using Water.Web.Controls;

namespace Water.Web.Controls.Design
{
    public class ContainerControlDesigner :ControlDesigner
    {
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            SetViewFlags(ViewFlags.TemplateEditing, true);
        }

        public override string GetDesignTimeHtml()
        {
            Container container = this.Component as Container;
            if (container != null)
            {
                if (container.EditTemplate == null && container.ItemTemplate == null && container.InsertTemplate==null && container.QueryTemplate==null)
                {
                    return CreatePlaceHolderDesignTimeHtml(MessageResource.EmptyTemplatePrompt);
                }
            }
            return base.GetDesignTimeHtml();
        }
        public override void UpdateDesignTimeHtml()
        {
            base.UpdateDesignTimeHtml();
        }
        public override void OnComponentChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs ce)
        {
            base.OnComponentChanged(sender, ce);
            UpdateDesignTimeHtml();
        }
        private TemplateGroupCollection templateGroups;
        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                if (this.templateGroups == null)
                {
                    templateGroups = base.TemplateGroups;

                    string _headerTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("HeaderTemplate");
                    TemplateGroup _headerTemplate = new TemplateGroup(_headerTemplatePrompt);
                    _headerTemplate.AddTemplateDefinition(new TemplateDefinition(this, _headerTemplatePrompt, this.Component, "HeaderTemplate", false));
                    templateGroups.Add(_headerTemplate);

                    string _footerTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("FooterTemplate");
                    TemplateGroup _footerTemplate = new TemplateGroup(_footerTemplatePrompt);
                    _footerTemplate.AddTemplateDefinition(new TemplateDefinition(this, _footerTemplatePrompt, this.Component, "FooterTemplate", false));
                    templateGroups.Add(_footerTemplate);


                    string _itemTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("ItemTemplate");
                    TemplateGroup _itemTemplate = new TemplateGroup(_itemTemplatePrompt);
                    _itemTemplate.AddTemplateDefinition(new TemplateDefinition(this, _itemTemplatePrompt, this.Component, "ItemTemplate", false));
                    templateGroups.Add(_itemTemplate);

                    string _InsertTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("InsertTemplate");
                    TemplateGroup _insertTemplate = new TemplateGroup(_InsertTemplatePrompt);
                    _insertTemplate.AddTemplateDefinition(new TemplateDefinition(this, _InsertTemplatePrompt, this.Component, "InsertTemplate", false));
                    templateGroups.Add(_insertTemplate);

                    string _editTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("EditTemplate");
                    TemplateGroup _editTemplate = new TemplateGroup(_editTemplatePrompt);
                    _editTemplate.AddTemplateDefinition(new TemplateDefinition(this, _editTemplatePrompt, this.Component, "EditTemplate", false));
                    templateGroups.Add(_editTemplate);

                    string _queryTemplatePrompt = AssemblyResourceManager.MessageResource.GetString("QueryTemplate");
                    TemplateGroup _queryTemplate = new TemplateGroup(_queryTemplatePrompt);
                    _queryTemplate.AddTemplateDefinition(new TemplateDefinition(this, _queryTemplatePrompt, this.Component, "QueryTemplate", false));
                    templateGroups.Add(_queryTemplate);
                }
                return templateGroups;
            }
        }
    }
}
